'''
Created on 2010-1-7

@author: wangjo
'''
import mokomodel
import utility
import logging
import math

PAGE_LIMIT = 500

class homeHandler(utility.BaseRequestHandler):
    def get(self):
        self.redirect('/gallery')
        
class galleryHandler(utility.BaseRequestHandler):
    def get(self):
        page = self.pageHandler()
        offset = PAGE_LIMIT *(page -1)
        modelcount = mokomodel.model.get_topgirl_count()
        models = mokomodel.model.get_topgirls(PAGE_LIMIT, offset)
        totalpage = int(math.ceil(modelcount/float(PAGE_LIMIT)))
        self.generate('api.gallery.xml', {'topgirls':models, 'total': modelcount, 'page': page, 'totalpage':totalpage},)